Repository navigation
[DRAFT] [starvation] model android::Mutex and recognise custom scoped guards - #2182
Draft
VladimirMakaev wants to merge 1 commit into
Draft
VladimirMakaev wants to merge 1 commit into
VladimirMakaev wants to merge 1 commit into
Conversation
VladimirMakaev
force-pushed
the
starvation-android-mutex-guards
branch
from
October 3, 2026 21:53
798f678 to
4d5bd42
Compare
This was referenced Oct 4, 2026
VladimirMakaev
force-pushed
the
starvation-android-mutex-guards
branch
3 times, most recently
from
October 5, 2026 13:39
060720b to
fefb6ff
Compare
Starvation knows a fixed list of scoped guards. With others (eg android::Mutex::Autolock), the
constructor's lock was read as a caller lock, so all guards became one lock: inversions were
missed and self deadlocks reported.
```cpp
#include <mutex>
struct Guard {
explicit Guard(std::mutex& m) : m_(m) { m_.lock(); }
~Guard() { m_.unlock(); }
std::mutex& m_;
};
class C {
std::mutex mu1_, mu2_;
public:
void thread1() { Guard a(mu1_); Guard b(mu2_); } // false positive: self deadlock
void thread2() { Guard b(mu2_); Guard a(mu1_); } // same; Infer missed: deadlock with thread1
};
```
Callee locks are substituted for all arguments and call depths, except through a local's address;
locks held on an object the caller cannot name are kept. A local whose constructor or by-value
return leaves one lock held guards it if its destructor releases one lock. A lock a callee
released before an event is not held by callers there. android::Mutex and Autolock are modelled,
tryLock and timedLock as trylocks; RacerD reports races in classes using them.
Limitations:
- a destructor that unlocks only on some paths (eg `if (owns_)`) makes no guard
- a lock released through a local C guard struct stays held (FP_guard_wm1_wm2_ok)
- a non-guard local's constructor lock is released at once (FN_acquirer_held_bad)
## Test plan
New tests in c/starvation/lock_wrappers.c, cpp/starvation (android_mutex.cpp, custom_guards.cpp,
release_in_callee.cpp, substitution.cpp), cpp/racerd/android_mutex.cpp and
java/starvation/Parameters.java, with FP_/FN_ tests for the limitations. The codetoanalyze tests
pass.
VladimirMakaev
force-pushed
the
starvation-android-mutex-guards
branch
from
October 5, 2026 18:14
fefb6ff to
62d50d0
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Starvation knows a fixed list of scoped guards. With others (eg android::Mutex::Autolock), the
constructor's lock was read as a caller lock, so all guards became one lock: inversions were
missed and self deadlocks reported.
Callee locks are substituted for all arguments and call depths, except through a local's address;
locks held on an object the caller cannot name are kept. A local whose constructor or by-value
return leaves one lock held guards it if its destructor releases one lock. A lock a callee
released before an event is not held by callers there. android::Mutex and Autolock are modelled,
tryLock and timedLock as trylocks; RacerD reports races in classes using them.
Limitations:
if (owns_)) makes no guardTest plan
New tests in c/starvation/lock_wrappers.c, cpp/starvation (android_mutex.cpp, custom_guards.cpp,
release_in_callee.cpp, substitution.cpp), cpp/racerd/android_mutex.cpp and
java/starvation/Parameters.java, with FP_/FN_ tests for the limitations. The codetoanalyze tests
pass.